< previous page page_388 next page >

Page 388
Chapter Objectives
Learn to create class modules
Learn to create some reusable classes
Learn to set default properties
Examples Filename: \Chapter20\OOP.vbp
Visual Basic Class Modules
Visual Basic CLS files contain all the properties and methods for your classes. Classes can be created in two different ways in Visual Basic: You can select Project, Add Class Module from the Visual Basic menu, or you can select the Class Builder Utility from the Add-Ins menu.
Once you create a CLS file, you need to identify what types of internal data you need to hold in the class. You create Private variables in the General Declarations area of the class module to hold this data. Then you need to decide which properties you want to give read access and which properties you want to give write access.
You can decide which private data to give read and write access by using Property Get and Property Let procedures in your class. A Property Get procedure is like a function that returns information about a Private variable. A Property Let is like a procedure you can use to set information in a Private variable. Theres also the Property Set procedure, which can be used to pass in an object reference to your class.
Creating a Simple Class
The first class youll build will track information about an employee. Youll create a class called Employee that contains the properties EmpID, FirstName, LastName, and Salary. To build this class, use the steps outlined in the following exercise.
EXERCISE
Creating a Class Module
1. Create a new project using the Standard EXE template.
2. Insert a CLS file by selecting Project, Add Class Module.

 
< previous page page_388 next page >

If you like this book, buy it!